package com.example.pcl.controller.user;


import com.example.pcl.constant.MessageConstants;
import com.example.pcl.pojo.dto.AnnouncementQueryDTO;
import com.example.pcl.result.Result;
import com.example.pcl.service.IAnnouncementsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 公告表，系统公告或重要信息发布 前端控制器
 * </p>
 *
 * @author xx
 * @since 2024-12-17
 */
@RestController("userAnnouncementsController")
@RequestMapping("/user/announcement")
@Slf4j
@RequiredArgsConstructor
@Tag(name = "用户端公告相关接口")
public class AnnouncementsController {

    private final IAnnouncementsService announcementService;


    /**
     * 分页查询公告
     *
     * @param queryDTO dto
     * @return 分页后的公告列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询公告")
    public Result<?> searchAnnouncements(@Validated AnnouncementQueryDTO queryDTO) {
        log.info("用户分页查询公告:{}", queryDTO);
        return Result.success(announcementService.pageList(queryDTO), MessageConstants.SELECT_OK);
    }

    /**
     * 获取公告详细
     *
     * @param id 公告id
     * @return 公告实体
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取公告详情")
    public Result<?> getAnnouncement(@PathVariable Integer id) {
        log.info("用户获取公告详细:{}", id);
        return Result.success(announcementService.getAnnouncementById(id), MessageConstants.SELECT_OK);
    }
}
